package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.LeaseAgreementService;
import com.atguigu.lease.web.app.service.UserInfoService;
import com.atguigu.lease.web.app.vo.agreement.AgreementDetailVo;
import com.atguigu.lease.web.app.vo.agreement.AgreementItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.language.bm.Rule;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private GraphInfoMapper graphInfoMapper;

    @Override
    public List<AgreementItemVo> customGetByUserId(Integer id) {
        UserInfo userInfo = userInfoService.getById(id);
        String phone = userInfo.getPhone();
        List<AgreementItemVo> agreementItemVos = leaseAgreementMapper.customSelectByUserId(phone);
        return agreementItemVos;
    }

    @Override
    public AgreementDetailVo customGetById(Long id) {
        AgreementDetailVo agreementDetailVo = leaseAgreementMapper.customSelectById(id);
        Long apartmentId = agreementDetailVo.getApartmentId();
        List<GraphVo> graphVosOfAp = graphInfoMapper.customSelectByApId(apartmentId);
        agreementDetailVo.setApartmentGraphVoList(graphVosOfAp);
        Long roomId = agreementDetailVo.getRoomId();
        List<GraphVo> graphVosOfRoom = graphInfoMapper.customSelectByRoomId(roomId);
        agreementDetailVo.setRoomGraphVoList(graphVosOfRoom);

        return agreementDetailVo;
    }
}




